package test;

//计算布尔二叉树的值:https://leetcode.cn/problems/evaluate-boolean-binary-tree/description/
public class EvaluateTree {

	public boolean dfs(TreeNode root){
        if(root==null) return true;
        
        if(root.left==null&&root.right==null){
            return root.val==0?false:true;
        }
        boolean leftVal=dfs(root.left);   //获得左值
        boolean rightVal=dfs(root.right); //获得右值
        return root.val==2?leftVal||rightVal:leftVal&&rightVal;
    }
	
    public boolean evaluateTree(TreeNode root) {
        return dfs(root);
    }

}
